package com.imot.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * @author ning.wang
 * @since 2023/5/25
 */

@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    //新增时自动填充
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject,"createTime", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject,"createtime", LocalDate.class,LocalDate.now());
        this.strictInsertFill(metaObject,"permission", Integer.class,1);
        this.strictInsertFill(metaObject,"modifiedTime", LocalDateTime.class,LocalDateTime.now());
        this.strictInsertFill(metaObject,"isDeleted",Boolean.class,false);
    }

    //修改时自动填充
    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject,"modifiedTime",LocalDateTime.class, LocalDateTime.now());
    }
}
